package com.usian.admin.controller;

import com.usian.admin.service.AdChannelService;
import com.usian.apis.admin.AdChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/v1/channel")
@Api(value = "频道管理" ,tags = "AdChannel", description = "频道管理API")
public class AdChannelController implements AdChannelControllerApi {
    @Autowired
    private AdChannelService service;

    @PostMapping("list")
    @Override
    @ApiOperation(value = "查询频道信息",notes = "根据名称分页查询频道列表")
    @ApiImplicitParam(name = "channelDto",type ="ChannelDto",value = "查询名称")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto channelDto) {
        return service.findByNameAndPage(channelDto);
    }

    @Override
    @PostMapping("save")
    @ApiOperation(value = "插入频道信息",notes = "插入频道信息")
    @ApiImplicitParam(name = "channel",type ="AdChannel",value = "AdChannel对象插入")
    public ResponseResult save(@RequestBody AdChannel channel) {
        return service.insert(channel);
    }

    @Override
    @PostMapping("update")
    @ApiOperation(value = "修改频道信息",notes = "修改频道信息")
    @ApiImplicitParam(name = "channel",type ="AdChannel",value = "AdChannel对象修改")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return service.update(adChannel);
    }

    @Override
    @GetMapping("del/{id}")
    @ApiOperation(value = "删除频道信息",notes = "删除频道信息")
    @ApiImplicitParam(name = "id",type ="Integer",value = "AdChannel对象删除")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return service.deleteById(id);
    }

    @GetMapping("channels")
    @Override
    public ResponseResult findAll() {
        List<AdChannel> list = service.list();
        return ResponseResult.okResult(list);
    }

}
